package ControlLayer;

import java.util.ArrayList;
import DBLayer.DbSupplier;
import ModelLayer.Supplier;

public class CtrSupplier {
	
	DbSupplier dbSup;
	Supplier sup;
	
	public CtrSupplier(){
		dbSup = new DbSupplier();
		sup = new Supplier();
	}
	
	public ArrayList<Supplier> getAll() {
		return dbSup.getAll();
	}

	
	public Supplier find(String name) {
		return dbSup.find(name);
	}
	
	public Supplier find_byID(int id) {
		return dbSup.find_byID(id);
	}
	
	
	public Supplier find_byCVR(String cvr) {
	return dbSup.find_byCVR(cvr);
	}
	
	public int delete(int sid){
	return dbSup.delete(sid);
	}
	
	
	public int insert(int pid, String name, String address, String phoneNo, String email, String companyName, String cvr) {
		
		Supplier sup = new Supplier(-1,name,address,phoneNo,email,companyName,cvr);
		
		int rc = -1;
		try {
			rc = dbSup.insert(sup);
		} catch (Exception e) {
		
			e.printStackTrace();
		}
		return rc;
	}

	
	public int update(int sid, String name, String address, String phoneNo, String email, String companyName, String cvr) {
		
		Supplier sup = new Supplier(sid,name,address,phoneNo,email,companyName,cvr);
		
		return dbSup.update(sup);
		
	}
		
	
}
